package com.justgame.project.service.api.dto;

import com.justgame.project.cloud.common.util.TokenUtil;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 登录成功后返回给前端
 * VO
 */
@Data
public class LoginedInfoModel {
    private String userid;
    private String uname;
    private String email;
    private String phone;
    private String sex;
    private String loginTime;
    private String onlineId;
    private String onlineName;
    private String onlineLevel;
    private String JCoins;
    private String images;
    private String onlineIntegral;
    private String onlineText;
    private String token;
    private String timeout;
    private String isAdmin;
    private String statusId;
    private String createDate;
    private String finalDate;
    private Integer isVip;
    private Date vipExpireDate;
    private Integer vipType;

    public LoginedInfoModel() {
    }

    public LoginedInfoModel(String userid, String uname, String email,
                            String phone, String sex, String loginTime,
                            String onlineId, String onlineName, String onlineLevel,
                            String JCoins, String images, String onlineIntegral,
                            String onlineText, String token, String timeout,
                            String isAdmin, String statusId, String createDate,
                            String finalDate,Integer isVip,Date vipExpireDate,Integer vipType) {
        this.userid = userid;
        this.uname = uname;
        this.email = email;
        this.phone = phone;
        this.sex = sex;
        this.loginTime = loginTime;
        this.onlineId = onlineId;
        this.onlineName = onlineName;
        this.onlineLevel = onlineLevel;
        this.JCoins = JCoins;
        this.images = images;
        this.onlineIntegral = onlineIntegral;
        this.onlineText = onlineText;
        this.token = token;
        this.timeout = timeout;
        this.isAdmin = isAdmin;
        this.statusId = statusId;
        this.createDate = createDate;
        this.finalDate = finalDate;
        this.isVip = isVip;
        this.vipExpireDate = vipExpireDate;
        this.vipType = vipType;
    }

    public LoginedInfoModel(LoginedInfoModel loginedinfomodel, String token) {
        this.createDate = loginedinfomodel.getCreateDate();
        this.statusId = loginedinfomodel.getStatusId();
        this.isAdmin = loginedinfomodel.getIsAdmin();
        this.onlineName = loginedinfomodel.getOnlineName();
        this.onlineLevel = loginedinfomodel.getOnlineLevel();
        this.JCoins = loginedinfomodel.getJCoins();
        this.images = loginedinfomodel.getImages();
        this.onlineIntegral = loginedinfomodel.getOnlineIntegral();
        this.onlineText = loginedinfomodel.getOnlineText();
        this.userid = loginedinfomodel.getUserid();
        this.uname = loginedinfomodel.getUname();
        this.email = loginedinfomodel.getEmail();
        this.phone = loginedinfomodel.getPhone().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
        this.sex = "2".equals(loginedinfomodel.getSex()) ? "未知" :
                "1".equals(loginedinfomodel.getSex()) ? "女" :
                        "0".equals(loginedinfomodel.getSex()) ? "男" : "未知";
        this.loginTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        this.onlineId = loginedinfomodel.getOnlineId();
        this.finalDate = loginedinfomodel.getFinalDate();
        if (StringUtils.isNotBlank(token)){
            this.timeout = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(TokenUtil.parseJWT(token).getExpiration());
            this.token = token;
        }
        this.isVip = loginedinfomodel.getIsVip();
        this.vipExpireDate = loginedinfomodel.getVipExpireDate();
        this.vipType = loginedinfomodel.getVipType();
    }

}
